package com.it9.taotao.manager.service.impl;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.it9.taotao.base.VO.ItemCatResponse;
import com.it9.taotao.manager.dao.IItemCatDao;
import com.it9.taotao.manager.pojo.TbItemCat;
import com.it9.taotao.manager.service.IItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ItemCatServiceImpl implements IItemCatService {

    @Autowired
    private IItemCatDao itemCatDao;

    @Override
    public List<ItemCatResponse> listItemCatByParentId(String parentId) {
        List<ItemCatResponse> itemCatResponseList = Lists.newArrayList();

        List<TbItemCat> tbItemCats = itemCatDao.listTbItemCatByParentId(parentId);

        for (TbItemCat tbItemCat : tbItemCats) {
            ItemCatResponse itemCatResponse = new ItemCatResponse();
            itemCatResponse.setId(tbItemCat.getId());
            itemCatResponse.setText(tbItemCat.getName());
            if (!tbItemCat.getIsParent()) {
                itemCatResponse.setState(ItemCatResponse.STATE_OPEN);
            }

            itemCatResponseList.add(itemCatResponse);
        }
        return itemCatResponseList;
    }
}
